package com.src.myapplication.ui.view.fragmentpemgyou;

import android.content.Context;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.src.myapplication.R;
import com.src.myapplication.base.BaseFragment;
import com.src.myapplication.base.ISQLdata;
import com.src.myapplication.ui.contor.SQLpresenter;

/**
 * Created by Administrator on 2016/10/17.
 */
public class FrgmentHaoYou extends BaseFragment implements ISQLdata {

    private ListView list;

    private SQLpresenter SQLpresenter;
    private int mPosition;

    @Override
    public void initView(View view) {
        list= (ListView) view.findViewById(R.id.list);
        SQLpresenter=new SQLpresenter(this);
        SQLpresenter.query();
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });
    }
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        getActivity().getMenuInflater().inflate(R.menu.main,menu);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_haoyou;
    }



    @Override
    public void addAdapter(SimpleCursorAdapter adapter) {
        if(adapter!=null){
            list.setAdapter(adapter);
        }

    }

    @Override
    public Context getIScontext() {
        return getContext();
    }

    @Override
    public String deleid() {
        return null;
    }

    //菜单的点击事件
    @Override
    public boolean onContextItemSelected(MenuItem item) {
        ContextMenu.ContextMenuInfo menuInfo = item.getMenuInfo();
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        mPosition = info.position;
        switch (item.getItemId()){
            //取消 什么都不做
            case R.id.action_update:


                break;
            //删除
            case R.id.action_delete:
//                SQLpresenter.delect();
                break;
        }

        return super.onContextItemSelected(item);
    }

}